package gold.digger;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC263 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        // only contains 2  3  5
        public boolean isUgly(int num) {
            if (num <= 0) return false;
            if (num == 1) return true;
            Set<Integer> dict = new HashSet<>(Arrays.asList(2, 3, 5));
            while (num > 0) {
                boolean isDivide = false;
                for (Integer di : dict) {
                    if (num == di) return true;
                    if (num % di == 0) {
                        num /= di;
                        isDivide = true;
                    }
                }

                if (!isDivide) return false;
            }

            return true;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.isUgly(-2147483648));
    }

    public static void main(String[] args) throws Exception {
        LC263 an = new LC263();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
